package com.zjmzxfzhl.modules.purchase.controller.dto;


import cn.hutool.core.util.StrUtil;
import com.zjmzxfzhl.modules.purchase.entity.PurchaseContract;
import com.zjmzxfzhl.modules.purchase.entity.PurchaseIndent;
import com.zjmzxfzhl.modules.purchase.entity.PurchaseMaterial;
import com.zjmzxfzhl.modules.purchase.entity.PurchaseProject;
import com.zjmzxfzhl.modules.purchase.entity.PurchaseSupplier;
import com.zjmzxfzhl.modules.purchase.service.bo.PurchaseOrderExcelBo;
import lombok.Getter;
import lombok.Setter;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;

/**
 * @Author timyag
 * @Date 2020/6/28 10:21
 * @Version 1.0
 */
@Getter
@Setter
public class PurchaseOrderDetailUpdateDto {
    private Long id;
    private Integer xh;
    private String materialCode;
    @NotBlank(message = "设备名称不能为空")
    private String materialName;
    private String materialSpecification;
    private String unit;
    @NotNull(message = "数量不能为空")
    private BigDecimal materialNum;
    @NotNull(message = "单价不能为空")
    private BigDecimal unitPrice;
    private BigDecimal materialTotalPrice;
    @NotBlank(message = "项目不能为空")
    private String projectName;
    @NotBlank(message = "采购单编号不能为空")
    private String indentCode;

    private String contractCode;

    @NotBlank(message = "供应商不能为空")
    private String supplierName;

    public PurchaseOrderDetailUpdateDto() {

    }

    public PurchaseOrderDetailUpdateDto(PurchaseOrderExcelBo excelBo) {
        this.setXh(excelBo.getXh());
        this.setMaterialCode(excelBo.getEquipmentCode());
        this.setMaterialName(excelBo.getEquipmentName());
        this.setMaterialSpecification(excelBo.getSpecification());
        this.setUnit(excelBo.getUnit());
        this.setMaterialNum(excelBo.getEquipmentNum());
        this.setUnitPrice(excelBo.getEquipmentUnitPrice());
        this.setMaterialTotalPrice(excelBo.getEquipmentTotalPirce());
        this.setProjectName(excelBo.getOrderUsage());
        this.setIndentCode(excelBo.getIndentCode());
        this.setSupplierName(excelBo.getSupplier());
    }

    public PurchaseMaterial genMaterialEntity() {
        PurchaseMaterial material = new PurchaseMaterial();
        material.setMaterialName(StrUtil.trim(this.materialName));
        material.setMaterialSpecification(StrUtil.trim(this.materialSpecification));
        material.setMaterialCode(StrUtil.trim(this.materialCode));
        material.setUnit(StrUtil.trim(this.unit));
        material.setUnitPrice(this.unitPrice);
        return material;
    }

    public PurchaseSupplier genSupplierEntity() {
        PurchaseSupplier supplier = new PurchaseSupplier();
        supplier.setSupplierName(StrUtil.trim(this.supplierName));

        return supplier;
    }

    public PurchaseProject genProjectEntity() {
        PurchaseProject project = new PurchaseProject();
        project.setProjectName(this.projectName);
        return project;
    }

    /**
     * 获取采购订单
     *
     * @return
     */
    public PurchaseIndent genIndentEntity() {
        PurchaseIndent indent = new PurchaseIndent();
        indent.setIndentCode(this.indentCode);
        return indent;
    }

    /**
     * 获取采购订单
     *
     * @return
     */
    public PurchaseContract genContractEntity() {
        PurchaseContract contract = new PurchaseContract();
        contract.setContractCode(this.contractCode);
        return contract;
    }
}

